﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using CommonLib;

namespace VectorOperationBenchmark {
    class Program {
        public static uint LOOP = 1000 * 1000 * 100;
        public static Stopwatch swatch = new Stopwatch();
        static void Main(string[] args) {
            Console.WriteLine("Loops=" + LOOP);

            testDestClass();

            Console.Out.Flush();
            int ch = Console.In.Read();
        }
        public static void testDestClass() {
            // diag
            Console.WriteLine("==== Destructive Class ====");
            Vector3c sumc;
            Vector3c biasc = new Vector3c(1.0, 1.0, 1.0);
            Vector3c gainc = new Vector3c(1.1, 1.1, 1.1);
            Vector3c elemc = new Vector3c(1.3, 1.3, 1.3);

            // add
            sumc = new Vector3c();
            swatch.Reset();
            swatch.Start();
            for (uint i = 0; i < LOOP; i++) {
                sumc.add(elemc);
            }
            swatch.Stop();
            Console.WriteLine("Add\t" + swatch.Elapsed);

            // sub
            sumc = new Vector3c();
            swatch.Reset();
            swatch.Start();
            for (uint i = 0; i < LOOP; i++) {
                sumc.sub(elemc);
            }
            swatch.Stop();
            Console.WriteLine("Sub\t" + swatch.Elapsed);

            // mul
            sumc = new Vector3c();
            swatch.Reset();
            swatch.Start();
            for (uint i = 0; i < LOOP; i++) {
                sumc.mul(gainc);
            }
            swatch.Stop();
            Console.WriteLine("Mul\t" + swatch.Elapsed);

            // div
            sumc = new Vector3c();
            swatch.Reset();
            swatch.Start();
            for (uint i = 0; i < LOOP; i++) {
                sumc.div(gainc);
            }
            swatch.Stop();
            Console.WriteLine("Div\t" + swatch.Elapsed);

            //mac
            sumc = new Vector3c();
            swatch.Reset();
            swatch.Start();
            for (uint i = 0; i < LOOP; i++) {
                sumc.mac(gainc, elemc);
            }
            swatch.Stop();
            Console.WriteLine("Mac\t" + swatch.Elapsed);

            // dot
            double dotc;
            swatch.Reset();
            swatch.Start();
            for (uint i = 0; i < LOOP; i++) {
                dotc = elemc.dot(gainc);
            }
            swatch.Stop();
            Console.WriteLine("Dot\t" + swatch.Elapsed);

            // norm
            double distc;
            swatch.Reset();
            swatch.Start();
            for (uint i = 0; i < LOOP; i++) {
                distc = elemc.norm();
            }
            swatch.Stop();
            Console.WriteLine("Norm\t" + swatch.Elapsed);

            // normalize
            sumc = new Vector3c(elemc);
            swatch.Reset();
            swatch.Start();
            for (uint i = 0; i < LOOP; i++) {
                sumc.normalize();
            }
            swatch.Stop();
            Console.WriteLine("Normal\t" + swatch.Elapsed);

        }
    }
}
